# -*-cperl-*-
use strict;
use warnings FATAL => 'all';
use blib;
use FindBin;
use lib $FindBin::Bin . '/lib';

use IO::Prompt;
use IoPromptTestUtils;

my $test_count = 0;
$TEST_COUNT_REF = \$test_count;
use Test::More;


# Variations on the yes/no theme...
#
@INJECT_INPUT_HOOKS = ( single_char_answer('Y') );
#@PROMPT_CHECK_HOOKS = ( match_prompt(qr{^Continue char \(Y/N\): $}, 'Both capitals single char should match prompt') );

prompt(-YN1,    "Continue char (Y/N): ");

#1 until prompt(-YN1,    "Continue char (Y/N): ");
#1 until prompt(-yn1,    "Continue char (y/n): ");
#1 until prompt(-yesno1, "Continue char (y/n): ");
#1 until prompt(-yes1,   "Continue char (y/*): ");
#1 until prompt(-YES1,   "Continue char (Y/*): ");
#1 until prompt(-Y1,     "Continue char (Y/*): ");
#1 until prompt(-yn,     "Continue line (y/n): ");
#1 until prompt(-yes,    "Continue line (y/*): ");
#1 until prompt(-YN,     "Continue line (Y/N): ");
#1 until prompt(-Y,      "Continue line (Y/*): ");

done_testing($test_count);


sub single_char_answer {
    my $char = shift;
    return sub {
        my ($TEST_COUNTER, $IN, $OUT) = @_;
        syswrite($IN, $char);
    };
}

sub match_prompt {
    my $regex = shift;
    my $test_label = shift;
    return sub {
        my ($TEST_COUNTER, $OUT) = @_;
        my $prompt = join '', <$OUT>;
        like($prompt, $regex, $test_label);
        $$TEST_COUNTER++;
    };
}
